
{% include "iframe_header" %}

<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">资产</label>
                            <div class="layui-input-inline">
                                <select name="symbol">
                                    <option value="">请选择</option>
                                    {% range $k,$v := .all_symbols %}
                                    <option value="{%$v.Symbol%}">{%$v.Name%}/{%$v.Symbol%}</option>
                                    {%end%}
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户</label>
                            <div class="layui-input-inline">
                                <input type="text" name="user_id" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        
                        
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            <button type="reset" class="layui-btn layui-btn-primary">清空</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container" style="display: none;">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs freeze" lay-event="freeze">冻结记录</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger assets_log" lay-event="assets_log">变动记录</a>
        </script>

    </div>
</div>


<script>
    layui.use(['form', 'table','element'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/admin/user/assets?api=1',
            //toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            where: {"searchParams": {% .search | json %}},
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'user_id', title: '用户ID'},
                {field: 'symbol', title: '资产'},
                {field: 'total', title: '余额', templet: function(d){
                    return utils.format_num(d.total);
                }},
                {field: 'avail', title: '可用', templet: function(d){
                    return utils.format_num(d.avail);
                }},
                {field: 'freeze', title: '冻结', templet: function(d){
                    return utils.format_num(d.freeze);
                }},
                
                {field: 'create_time', width: 180, title: '创建时间', templet: function(d){
                    return utils.format_timestamp(d.create_time*1000);
                }},
                {field: 'update_time', width: 180, title: '更新时间', templet: function(d){
                    return utils.format_timestamp(d.update_time*1000);
                }},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });


        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            console.log(data);
            var args = '{"symbol":"'+ data.symbol +'","user_id": "'+data.user_id+'"}';
                
            if (obj.event === 'edit') {
                
            } else if (obj.event === 'freeze') {
                utils.open_url(data.user_id+'的'+ data.symbol +'冻结日志', '/admin/user/assets/freeze?searchParams='+ encodeURIComponent(args));

            } else if (obj.event === 'assets_log') {
                utils.open_url(data.user_id+'的'+ data.symbol +'变动日志', '/admin/user/assets/logs?searchParams='+encodeURIComponent(args));
            }
        });


        form.val("searchForm", JSON.parse({% .search | json %}));
        form.render();
    });
</script>

{% include "iframe_footer" %}